﻿using System.Globalization;
using System.Windows.Data;

namespace VideoTools.Converters
{
    public class IndexToGridPositionConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null || values.Length < 2)
                return 0;

            // 第一个值是 AlternationIndex (int)
            if (values[0] is int index)
            {
                // 第二个值是参数 ("Row" 或 "Column")
                if (values[1] is string type)
                {
                    if (type == "Row")
                        return index / 2;  // 行号 = 索引 / 2
                    else if (type == "Column")
                        return index % 2;  // 列号 = 索引 % 2
                }
            }
            return 0;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
